import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "vite-plugin-vue-setup-extend";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), Components()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: '0.0.0.0',//监听所有可用的接口
    proxy: {
      // 使用 proxy 实例将请求代理到后端服务
      '/api': {
        // 代理目标地址
        target: 'https://uniqueker.top/connect.php',
        // 改变源地址，看起来像是目标服务器发送的请
        changeOrigin: true,
        //将/api重写为空，让请求路径更简洁
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
});
